package com.yyfax.account.service;

import com.jaws.core.common.log.Log;
import com.yyfax.account.vo.BaseTradeReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 批量操作交易或结算服务类
 *
 * @author liangqm
 * @date 2017-11-08 08:45:26
 * @since v1.0.0
 */
@Service
public class BatchOperationService {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	private AccountTradeFactory tradeFactory;

	/**
	 * 处理批量交易
	 *
	 * @author liangqm
	 * @date 2017-11-08 18:45:24
	 * @since v1.0.0
	 * @param tradeLs 交易集合
	 */
	@Transactional
	public void handleBatchOperation(List<BaseTradeReq> tradeLs) {
		final String OP = "AccountTradeServiceImpl.batchTrade";
		logger.info(Log.op(OP).msg("批量交易操作数据库开始").toString());
		// 交易
		for (BaseTradeReq trade : tradeLs) {
			tradeFactory.getAdaptiveTradeService(trade.getTradeType()).doTrade(trade, true);
		}
		logger.info(Log.op(OP).msg("批量交易操作数据库结束").toString());
	}
}
